#region Using Statements

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;

// Note:  Before you can build this file in a project, you must
//        add a reference to System.xml. To to this, right-click
//        on References in Solution Explorer and click Add Reference.
//        In the .NET pane, scroll down and select System.Xml.

// Additional Using Statments Needed for the Storage Functions.
using System.IO;
using System.Xml.Serialization;

#endregion

namespace GameFramework.StorageSystem
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class StorageManager : Microsoft.Xna.Framework.GameComponent
    {
        /// <summary>
        /// Storage Manager Controls all of the Storage Functions for your
        /// Game or Application
        /// </summary>
        /// <param name="game"></param>
        /// <param name="Container">Name of the Storage Contianer</param>
        /// <param name="FilenameGameOptions">Filename for the Game Options Save File</param>
        /// <param name="FilenamePlayerData">Filename for the Player Data Save File</param>
        public StorageManager(Game game, string Container, string FilenameGameOptions, string FilenamePlayerData)
            : base(game)
        {
            // TODO: Construct any child components here
            this.gameOptionsFilename = FilenameGameOptions;
            this.playerDataFilename = FilenamePlayerData;
            this.containerName = Container;

            this.gameOptions = new GameOptions();
            this.playerData = new PlayerData();

        }


        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here

            // Setup the Default options for the Game
            gameOptions.MusicEnabled = true;
            gameOptions.SfxEnabled = true;

            base.Initialize();
        }


        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here

            base.Update(gameTime);
        }

        private string gameOptionsFilename;

        public string GameOptionsFilename
        {
            get { return gameOptionsFilename; }
            set { gameOptionsFilename = value; }
        }

        private string playerDataFilename;

        public string PlayerDataFilename
        {
            get { return playerDataFilename; }
            set { playerDataFilename = value; }
        }

        private string containerName;

        public string ContainerName
        {
            get { return containerName; }
            set { containerName = value; }
        }

        private GameOptions gameOptions;
                    
        public GameOptions GameOptions
        {
            get { return gameOptions; }
            set { gameOptions = value; }
        }

        private PlayerData playerData;

        public PlayerData PlayerData
        {
            get { return playerData; }
            set { playerData = value; }
        }

        public void LoadGameOptions()
        {
            //StorageDevice device = StorageDevice.ShowStorageDeviceGuide();

            //// Open a storage container
            //StorageContainer container = device.OpenContainer(this.containerName);

            //// Get the path of the save game
            //string tempFileName = Path.Combine(StorageContainer.TitleLocation, this.gameOptionsFilename);

            //// Check to see if the save exists
            //if (!File.Exists(tempFileName))
            //{
            //    // Set the Options to Default Values
            //    //this.gameOptions.MusicEnabled = false;
            //    //this.gameOptions.SfxEnabled = true;
            //}

            //// Open the file
            //FileStream stream = File.Open(tempFileName, FileMode.OpenOrCreate,
            //    FileAccess.Read);

            //// Read the data from the file
            //XmlSerializer serializer = new XmlSerializer(typeof(GameOptions));
            //this.gameOptions = (GameOptions)serializer.Deserialize(stream);

            //// Close the file
            //stream.Close();

            //// Dispose the container
            //container.Dispose();
        }

        public void SaveGameOptions()
        {
            //StorageDevice device = StorageDevice.ShowStorageDeviceGuide();
            //// Open a storage container
            //StorageContainer container = device.OpenContainer(this.containerName);
            //// Get the path of the save game
            //string tempFileName = Path.Combine(StorageContainer.TitleLocation, this.gameOptionsFilename);

            //// Open the file, creating it if necessary
            //FileStream stream = File.Open(tempFileName, FileMode.OpenOrCreate);

            //// Convert the object to XML data and put it in the stream
            //XmlSerializer serializer = new XmlSerializer(typeof(GameOptions));
            //serializer.Serialize(stream, this.gameOptions);

            //// Close the file
            //stream.Close();
            //// Dispose the container, to commit changes
            //container.Dispose();
        }

        public void LoadPlayerData()
        {
        }

        public void SavePlayerData()
        {
        }

    }
}


